#include "Globle.h"
#include "mLinkList.h"


mLinkList::mLinkList(void)
{	
	L = new struct LinkNode;
	L->data = 0;
	L->next = NULL;
	data = 0;

}
void mLinkList::Insert(int d)
{
	LinkList p = L;
	while(p->next)
	{
		if (p->next->data > d)
			break;
		p = p->next;
	}
	if (p->data != d)
	{
		LinkList q = new LinkNode;
		q->data = d;
		q->next = p->next;
		p->next = q;
	}
}

void mLinkList::Display()
{
	LinkList p = L;
	if (!L->next)
	{
		printf("the list is empty\n");
		return;
	}
	while(p->next)
	{
		printf("%d	",p->next->data);
		p = p->next;
	}	
	printf("%n");
}
void mLinkList::DeleteElem(int d)
{
	LinkList p = L;
	LinkList temp;
	while(p->next)
	{		
		if(p->next->data == d)
		{
			temp = p->next;
			p->next = p->next->next;
			delete temp;
			return;
		}
		if(p->next->data > d)
			return;
		p = p->next;
	}
}
void mLinkList::Clear()
{
	LinkList p = L->next;
	L->next = NULL;
	LinkList q;
	while(p)
	{
		q = p;
		p = p->next;
		delete q;
	}

}

LinkList mLinkList::GetList()
{
	return L->next;
}